package com.minelx.table.core.series.index;

import com.minelx.table.core.series.source.Source;

import java.util.Arrays;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public interface Indexes {
	long at(long index);

	long len();

	LongStream stream();

	default <R> Stream<R> stream(Source<R> source) {
		return stream().mapToObj(source::at);
	}

	static Indexes array(long[] indexes) {
		return new Indexes() {
			@Override
			public LongStream stream() {
				return Arrays.stream(indexes);
			}

			@Override
			public long len() {
				return indexes.length;
			}

			@Override
			public long at(long index) {
				return indexes[(int) index];
			}
		};
	}

	static Indexes range(long from, long to) {
		return new RangeIndexes(from, to);
	}
}
